package it.gameplanet.client.widgets;

import it.gameplanet.client.GamePlanetContext;
import it.gameplanet.client.utils.AbstractAsyncCallback;
import it.gameplanet.client.widgets.support.ContextMenuLabel;
import it.gameplanet.model.Categoria;
import it.gameplanet.service.GamePlanetService;

import java.util.HashMap;
import java.util.Map;

import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.TreeItem;

public class MasterCategoriaTreeItem extends Composite {

	public MasterCategoriaTreeItem(final String categoria) {

		Map<String, Command> menu = new HashMap<String, Command>();
		menu.put("Inserisci Categoria", new Command() {
			  public void execute() {
				    GamePlanetService.Utils.getGamePlanetServiceAsync().inserisciCategoria("Nuova Categoria",categoria, new AbstractAsyncCallback<Void>() {

						@Override
						public void onSuccess(Void result) {
						}
				    	
				    });					    
				    TreeItem thisTreeItem = GamePlanetContext.getArticoliTree().getItem(categoria);				
				    thisTreeItem.addItem(new CategoriaTreeItem(new Categoria("Nuova Categoria", categoria))).addItem(GamePlanetTree.LEAF);
			  }
		});
		
		initWidget(new ContextMenuLabel(categoria, menu));
	}
}
